--[[ Lambda Buffmod
     Part of LambdaUI made by Gaius
	 Graphics are made by Gaius
	 ------------------------------
	 Contact me in irc://phcnet.de/#wow-interface
--]]

local filePath = "Interface\\AddOns\\LambdaUI\\"
local genericFilePath = "Interface\\AddOns\\LambdaUI\\Generic\\"

--[[  Lambda Buff Class

--]]

function skin(buttonName, index, filter)
	local Lambda = getglobal(buttonName..index)
    local filePath = filePath.."Buff\\"
	
	local icon = getglobal(buttonName..index.."Icon") -- texture
	local count = getglobal(buttonName..index.."Count") -- fontString
	local duration = getglobal(buttonName..index.."Duration") -- fontstring
	local border = getglobal(buttonName..index.."Border") -- texture
	
	if Lambda then
		Lambda.SetAlpha = function() end
		Lambda:SetFrameLevel(index)
	if icon then
		Lambda:SetWidth(34)
		Lambda:SetHeight(33)
		icon:SetDrawLayer("BACKGROUND")
		icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
	end
		
	if duration then
		duration:ClearAllPoints()
		duration:SetPoint("BOTTOMLEFT",icon,"TOPRIGHT", -5, -5)
		duration:SetFontObject(nil)
		duration:SetFont(genericFilePath.."bold.ttf",8)
		duration:SetDrawLayer("OVERLAY")
	end
		
	if not border then
		border = getglobal(buttonName..index):CreateTexture(buttonName..index.."Border")
	end
	if border then	
		border:ClearAllPoints()
		border:SetPoint("TOPLEFT",Lambda:GetName(),"TOPLEFT",-7, 7)
		border:SetWidth(64)
		border:SetHeight(64)
		border:SetTexture(filePath.."Border.tga")
		border:SetDrawLayer("Border")
		border:SetTexCoord(0,1,0,1)
		border.SetTexCoord = function() end
		border:SetVertexColor(unpack(LambdaUI.ThemeSettings.Border))
	end
	
	table.insert(LambdaObjectTable,Lambda:GetName())
	end
	
end 

function TempSkin(elapsed)
	for i=1,2 do
	local Lambda = getglobal("TempEnchant"..i)
    local filePath = filePath.."Buff\\"
	
	local icon = getglobal("TempEnchant"..i.."Icon") -- texture
	local count = getglobal("TempEnchant"..i.."Count") -- fontString
	local duration = getglobal("TempEnchant"..i.."Duration") -- fontstring
	local border = getglobal("TempEnchant"..i.."Border") -- texture
	
	if Lambda then
		Lambda.SetAlpha = function() end
		Lambda:SetFrameLevel(0)
	if icon then
		Lambda:SetWidth(34)
		Lambda:SetHeight(33)
		icon:SetDrawLayer("BACKGROUND")
		icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
	end
		
	if duration then
		duration:ClearAllPoints()
		duration:SetPoint("BOTTOMLEFT",icon,"TOPRIGHT", -5, -5)
		duration:SetFontObject(nil)
		duration:SetFont(genericFilePath.."bold.ttf",8)
		duration:SetDrawLayer("OVERLAY")
	end
		
	if not border then
		border = getglobal("TempEnchant"..i):CreateTexture("TempEnchant"..i.."Border")
	end
	if border then	
		border:ClearAllPoints()
		border:SetPoint("TOPLEFT",Lambda:GetName(),"TOPLEFT",-7, 7)
		border:SetWidth(64)
		border:SetHeight(64)
		border:SetTexture(filePath.."Border.tga")
		border:SetDrawLayer("Border")
		border:SetTexCoord(0,1,0,1)
		border.SetTexCoord = function() end
		border:SetVertexColor(unpack(LambdaUI.ThemeSettings.Border))
	end
	
	table.insert(LambdaObjectTable,Lambda:GetName())
	end
	end
end 

function DurationSkin(buffButton, timeleft)
	local buffDuration = getglobal(buffButton:GetName().."Duration")
	if timeleft > 60 then
		timeleft = timeleft / 60
	end
	buffDuration:SetFormattedText("|cFFFFFFFF%i|r",timeleft)
	
end

TemporaryEnchantFrame:ClearAllPoints()
TemporaryEnchantFrame:SetPoint("TOPRIGHT",UIParent,"TOPRIGHT", -20, -12)
TemporaryEnchantFrame.SetPoint = function() end

hooksecurefunc("BuffButton_UpdateAnchors",skin)
hooksecurefunc("BuffFrame_Enchant_OnUpdate", TempSkin)
hooksecurefunc("BuffFrame_UpdateDuration", DurationSkin)